package com.cn.cash.baselib.retrofit;



import com.cn.cash.baselib.util.CNUtil;

import java.io.IOException;

import okhttp3.FormBody;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by CN on 2018-3-13.
 */

public class CNRequestInterceptor implements Interceptor{
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();

        if("POST".equals(request.method())){
            StringBuilder sb = new StringBuilder();
            if (request.body() instanceof FormBody) {
                FormBody body = (FormBody) request.body();
                for (int i = 0; i < body.size(); i++) {
                    sb.append(body.encodedName(i) + "=" + body.encodedValue(i) + ",");
                }
                sb.delete(sb.length() - 1, sb.length());
            }
            CNUtil.log("postParams:"+sb);
        }else{
            CNUtil.log("getParams:"+request.url().query());
        }
        return chain.proceed(request);
    }
}
